package gold.digger;

import gold.vo.ListNode;

/**
 * Created by fanzhenyu02 on 2020/3/1.
 */
public class LC92 {

    public ListNode reverseBetween(ListNode head, int m, int n) {
        if (m == 1) {
            return reverseTopN(head, n);
        }

        // 前进到反转的起点触发 base case
        head.next = reverseBetween(head.next, m - 1, n - 1);
        return head;
    }

    public ListNode successor;

    public ListNode reverseTopN(ListNode head, int n) {
        if (n == 1) {
            successor = head.next;
            return head;
        }

        ListNode last = reverseTopN(head.next, n - 1);
        head.next.next = head;
        head.next = successor;

        return last;
    }

    public static void main(String[] args) {
        LC92 an = new LC92();
        System.out.println();
    }
}
